package com.example.chapter11;


/**
 * 11.2.5.闭包
 */
public class ClosureTest {

    interface Play {
        void playGame();
    }

    final private String hour = "1";//被内部类访问的变量，必须为 final

    public void test1(final String h) {
        //成员内部类
        Play p = new Play() {
            @Override
            public void playGame() {
                System.out.println("playGame" + h + "小时");//在这里访问了传入的外部变量h
            }
        };
        p.playGame();
    }

    //测试写法
    public void main() {
        test1(hour);//在这里将外部变量hour传了进去
    }

}
